package com.dragon.concurrent.demo.demo;

public class VisibilityTest extends Thread {

    private boolean stop;

    @Override
    public void run() {
        int i = 0;
        while (!stop) {
            System.out.println(i+++ "");
        }
        System.out.println("finish loop, i = " + i);
    }

    public void stopIt() {
        this.stop = true;
    }

    public boolean getStop() {
        return this.stop;
    }

    public static void main(String[] args) throws InterruptedException {
        VisibilityTest visibilityTest = new VisibilityTest();
        visibilityTest.start();
        Thread.sleep(1000L);
        visibilityTest.stopIt();
        System.out.println("finish main");
        System.out.println(visibilityTest.getStop());
    }
}
